package cn.taichoo.server.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.TencentCloudImUtils;
import com.ruoyi.common.redis.service.RedisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author:  SSG
 */
@Tag (name = "APP-TencentCloudIM管理")
@RestController
@RequestMapping ("/tencentcloudim")
@Validated
public class TencentCloudImController {

    @Resource
    RedisService redisService;

    private static final String REDIS_IM_USER_SIG = "silence:im_user_sig:";

    @GetMapping("/getUserSig")
    @Operation(summary = "获得IM主表UserSig信息")
    @Parameter(name = "userId", description = "用户id", required = true)
    public R<String> getUserSig(@RequestParam("userId") String userId) {

        String key =REDIS_IM_USER_SIG + userId;
        String userSig = (String) redisService.getCacheObject(key);
        if (StringUtils.isEmpty(userSig)) {
            userSig = TencentCloudImUtils.getTxCloudUserSig(userId);
            redisService.setCacheObject(key, userSig, 86400L);
        }
        return R.ok ( userSig );
    }

}
